package com.bw.utils;

import java.util.Calendar;
import java.util.Date;

public class DateUtils {
	
	//求未来日期离今天还剩的天数
	public static int getDaysByFuture(Date Future) {
		Calendar c = Calendar.getInstance();
		long time = c.getTimeInMillis();
		c.setTime(Future);
		long mill = c.getTimeInMillis();
		long aa=mill-time;
		return (int) aa;
	}
	
	//求过去日期离今天过去的天数
	public static int getDaysByDeparted (Date departed) {
		
		
		return 0;
	}
	
	//根据传入的日期获取年龄
	public static int getAge (Date src) {
		Calendar c = Calendar.getInstance();
		int oyear = c.get(Calendar.YEAR);
		int omonth = c.get(Calendar.MONTH);
		int odate = c.get(Calendar.DAY_OF_MONTH);
		c.setTime(src);
		int nyear = c.get(Calendar.YEAR);
		int nmonth = c.get(Calendar.MONTH);
		int ndate = c.get(Calendar.DAY_OF_MONTH);
		
		int year=nyear-oyear;
		if(omonth>nmonth) {
			year--;
		}
		if(omonth>nmonth && odate>ndate) {
			year--;
		}
		return year;
	}
	
	//返回月初时间
	public static Date getDateByMonthInit (Date src) {
		Calendar c = Calendar.getInstance();
		
		return src;
	}
	
	//返回月末时间
	public static Date getDateByMonthLast(Date src) {
		Calendar c = Calendar.getInstance();
		
		
		return src;
	}
	
	
	
	
}
